const express = require('express')
const { zzshequModel } = require('../model/models')
const router = express.Router()

router.get('/zzshequ', async (req, res) => {
    const data = await zzshequModel.find()
    res.send({
        code: 200,
        data
    })
})
router.get('/search', async (req, res) => {
    data = await zzshequModel.find({ title: { $regex: req.query.title } })
    res.send({
        code: 200,
        data
    })
})
router.put('/gxihuan', async (req, res) => {
    const id = req.query.id
    // const ss = await zzshequModel.find({_id:id})
    const data = await zzshequModel.updateOne({ _id: id }, { xihuan: true })
    res.send({
        code: 200,
        data
    })
})

router.get('/zzxiang', async (req, res) => {
    const data = await zzshequModel.find({ _id: req.query.id })
    res.send({
        code: 200,
        data
    })
})

router.get('/searchyong', async (req, res) => {
    data = await jiaoModel.find({ name: { $regex: req.query.name } })
    res.send({
        code: 200,
        data
    })
})
router.put('/dianzan', async (req, res) => {
    const id = req.query.id
    const data = await zzshequModel.updateOne({ _id: id }, { dianzan: true })
    res.send({
        code: 200,
        data
    })
})
router.put('/qxdianzan', async (req, res) => {
    const id = req.query.id
    const data = await zzshequModel.updateOne({ _id: id }, { dianzan: false })
    res.send({
        code: 200,
        data
    })
})
router.get('/search', async (req, res) => {
    data = await zzshequModel.find({ title: { $regex: req.query.title } })

    res.send({
        code: 200,
        data
    })
})
router.put('/dianzan', async (req, res) => {
    const id = req.query.id
    const data = await zzshequModel.updateOne({ _id: id }, { dianzan: true })
    res.send({
        code: 200,
        data
    })
})
router.put('/qxdianzan', async (req, res) => {
    const id = req.query.id
    const data = await zzshequModel.updateOne({ _id: id }, { dianzan: false })
    res.send({
        code: 200,
        data
    })
})
router.get('/zzxiang', async (req, res) => {
    const data = await zzshequModel.find({ _id: req.query.id })
    res.send({
        code: 200,
        data
    })
})
module.exports = router